import Application from './application';
import DS from 'ember-data';

export default Application.extend(DS.EmbeddedRecordsMixin,{

    _serializeEmbeddedHasMany(snapshot, json, relationship) {
      this._super(snapshot, json, relationship);
      this._hasManyDataEmbedded(json, relationship)
    },

    _hasManyDataEmbedded(json, relationship) {
      if (relationship.kind != 'hasMany') {
        return;
      }
      let key = relationship.key.dasherize();
      let data = json[key].mapBy('data');
      delete json[key];
      //添加自定义段，把子表内容加载到此段
      if (!json.postPayload) {
        json.postPayload = {};
      }
      json.postPayload[key] = {
        data
      };
      json.postPayload.reverse = this.get("payloadReverse");
    },
});
